home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 45
/
Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso
/
Aminet
/
game
/
role
/
ldmud-3.2-bin.lha
/
mud
/
doc
/
efun
/
input_to
< prev
next >
Wrap
Text File
|
2001-04-03
|
4KB
|
96 lines
SYNOPSIS
#include <input_to.h>
void input_to(string|closure fun)
void input_to(string|closure fun, int flag, ...)
DESCRIPTION
Enable next line of user input to be sent to the function <fun>
as an argument. Exception: if the next input
line starts with a "!", it will be parsed as a command resp.
passed to the most recent input_to() given with the
INPUT_IGNORE_BANG flag.
The function <fun> may be static, but must not be private (or
it won't be found).
Note that fun is not called immediately but after pressing the
RETURN key.
If input_to() is called more than once in the same execution,
only the first call has any effect. On the other hand, if
a command given during an input_to() (using the "!" escape)
issues its own input_to(), the previous input_to() is suspended
until the new input_to() has been handled, then the previous
one becomes active again.
The optional argument <flag> may be a binary-OR ('|') of the
following option values:
INPUT_NOECHO (1):
The line given by the player will not be echoed, and is
not seen if snooped.
INPUT_CHARMODE (2):
The connection is switched from line- into charmode to
retrieve a single character(!) from the player.
After execution of <fun>, the connection is switched
back into linemode unless a subsequent input_to( , 2)
has been issued.
Lineends are received depending on how the client sends
them: either as "", as "\r" followed by "", or (happens
with Windows clients) as just "\r".
Note that the players frontend is free to stay in
linemode all the time: even if you request a single
character, the player might be forced to type (and send)
that character plus the return key. Usually your function
will then receive the complete input in one call.
If you plan to stay in charmode a longer time , you can
reduce the call overhead by using set_combine_charset()
to retrieve sequences of certain characters as one string
instead of one-by-one. In a screen-oriented editor for
example this would be most of the printable characters.
INPUT_IGNORE_BANG (128):
Input lines starting with '!' will _not_ be parsed as
commands, but are given to the function as well. Usage
of this option is privileged.
The optional 3rd and following args will be passed as second and
subsequent args to the function fun.
EXAMPLE
void func() {
...
write("Please enter your name:");
input_to("enter_name");
...
}
enter_name(string str) {
write("Is '"+str+"' really your name?? *giggle*\n");
...
}
When reaching the input_to() statement the driver
continues the function func() but also asks the user for
input. If you entered whatever is asked and press RETURN the
driver will invoke the enter_name() function with the
string you entered as argument to it.
HISTORY
The meaning of the flag parameter was extended in 3.2.1@93.
The limited "stacking" of input_to()s issued from !-commands
was implemented in LDMud 3.2.8.
Since LDMud 3.2.8 the function can be given as a closure.
BUGS
In CHARMODE, newlines should really be returned as "\n"; however,
this might break existing code.
SEE ALSO
call_other(E), sscanf(E), privilege_violation(M),
set_combine_charset(E)